package com.jeeplus.modules.web.service;

import com.jeeplus.core.persistence.DataEntity;
import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.service.CrudService;
import com.jeeplus.modules.web.entity.WxUserRoomQrcode;
import com.jeeplus.modules.web.mapper.WxUserRoomQrcodeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 棋牌室Service
 * @author liangbing
 * @version 2021-03-11
 */
@Service
@Transactional(readOnly = true)
public class WxUserRoomQrcodeService extends CrudService<WxUserRoomQrcodeMapper, WxUserRoomQrcode> {

    @Autowired
    private WxUserRoomQrcodeMapper wxUserRoomQrcodeMapper;

    public WxUserRoomQrcode get(String id) {
        return super.get(id);
    }

    public WxUserRoomQrcode getByRoomQrcode(String roomQrcode) {
        return wxUserRoomQrcodeMapper.getByRoomQrcode(roomQrcode, DataEntity.DEL_FLAG_NORMAL);
    }

    public List<WxUserRoomQrcode> findList(WxUserRoomQrcode wxUserRoomQrcode) {
        return super.findList(wxUserRoomQrcode);
    }

    public Page<WxUserRoomQrcode> findPage(Page<WxUserRoomQrcode> page, WxUserRoomQrcode wxUserRoomQrcode) {
        return super.findPage(page, wxUserRoomQrcode);
    }

    public Long count(WxUserRoomQrcode wxUserRoomQrcode) {
        return super.count(wxUserRoomQrcode);
    }

    @Transactional(readOnly = false)
    public void save(WxUserRoomQrcode wxUserRoomQrcode) {
        super.save(wxUserRoomQrcode);
    }

    @Transactional(readOnly = false)
    public void insertOrUpdate(WxUserRoomQrcode wxUserRoomQrcode) {

        // 判断是否已经存在
        WxUserRoomQrcode record = new WxUserRoomQrcode();
        record.setOpenid(wxUserRoomQrcode.getOpenid());
        Long count = wxUserRoomQrcodeMapper.count(record);
        if (count > 0L){
            wxUserRoomQrcodeMapper.update(wxUserRoomQrcode);
        } else {
            wxUserRoomQrcodeMapper.insert(wxUserRoomQrcode);
        }
    }


    @Transactional(readOnly = false)
    public void delete(WxUserRoomQrcode wxUserRoomQrcode) {
        super.delete(wxUserRoomQrcode);
    }
}
